﻿/*
 *  Sqlite ORM - PUBLIC DOMAIN LICENSE
 *  Copyright (C)  2010-2012. Ian Quigley
 *  
 *  This source code is provided 'As is'. You bear the risk of using it.
 */

using System.Collections.Generic;
using System.Data.SQLite;
using System.Linq;
using System;

namespace SqliteORM.Tests
{
	public class Context : IDisposable
	{
		public const string ConnectionString = "Data Source=test.db3";
        

        public Context()
        {
        
        }

		public static void Initialise()
		{
		}

        
		public static void DropTables()
		{
			using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
			{
				connection.Open();

				foreach (string name in TableNames().Where(n => !n.StartsWith("sqlite")))
				{
					SQLiteCommand cmd = new SQLiteCommand( "delete from " + name, connection );
					cmd.ExecuteNonQuery();
				}
			}
		}
        

		public static List<string> TableNames()
		{
			using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
			using (SQLiteCommand command = new SQLiteCommand("select name from sqlite_master where type='table'", connection))
			{
				connection.Open();
				SQLiteDataReader reader = command.ExecuteReader();
				List<string> names = new List<string>();

				while (reader.Read())
					names.Add((string)reader[0]);

				return names;
			}
		}


        public void Dispose()
        {
            throw new NotImplementedException();
        }
    }
}
